using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using Rilisoft;
using UnityEngine;

public class LicenseChecker : MonoBehaviour
{
	public static LicenseChecker instance;

	public GameObject gameLock;

	private void OnApplicationPause(bool pauseStatus)
	{
		if (!pauseStatus)
		{
			Start();
		}
	}

	public void CheckPackageName()
	{
		AndroidJavaObject @static = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
		string value = @static.Call<string>("getPackageName", new object[0]);
		if (!settings.GetPackageNameByStore(settings.typeStore.PlayStore).Equals(value))
		{
			Application.Quit();
		}
	}

	public static bool CheckHostsTampering()
	{
		if (Application.platform != RuntimePlatform.Android)
		{
			return false;
		}
		try
		{
			string[] source = File.ReadAllLines("/etc/hosts");
			IEnumerable<string> source2 = source.Where((string l) => l.TrimStart().StartsWith("127."));
			return source2.Any((string l) => l.Contains("android.clients.google.com") || l.Contains("mtalk.google.com "));
		}
		catch (Exception message)
		{
			BCWDebug.LogError(message);
			return false;
		}
	}

	public static bool CheckIosCrackersInstalled()
	{
		if (Application.platform != RuntimePlatform.IPhonePlayer)
		{
			return false;
		}
		if (File.Exists(Path.Combine("/Library/MobileSubstrate/DynamicLibraries", "LocalIAPStore.dylib")) || File.Exists(Path.Combine("/Library/MobileSubstrate/DynamicLibraries", "LocallAPStore.dylib")))
		{
			BCWDebug.LogWarning("Anti-cheat protection: LocalIAPStore detected.");
			return true;
		}
		if (File.Exists(Path.Combine("/Library/MobileSubstrate/DynamicLibraries", "iap.dylib")))
		{
			BCWDebug.LogWarning("Anti-cheat protection: IAP Cracker detected.");
			return true;
		}
		if (File.Exists(Path.Combine("/Library/MobileSubstrate/DynamicLibraries", "iapfree.core.dylib")) || File.Exists(Path.Combine("/Library/MobileSubstrate/DynamicLibraries", "IAPFreeService.dylib")))
		{
			BCWDebug.LogWarning("Anti-cheat protection: IAP Free detected.");
			return true;
		}
		return false;
	}

	private void Awake()
	{
		instance = this;
	}

	private void OnDestroy()
	{
		instance = null;
	}

	public void Start()
	{
	}

	public void GetLicense()
	{
		if (BCWDebug.isDebugBuild)
		{
			BCWDebug.LogWarning("Development build lic");
			return;
		}
		if (!CheckForInternetConnection())
		{
			BCWDebug.LogWarning("No connection");
			return;
		}
		LicenseVerificationManager licenseVerificationManager = LicenseVerificationManager.instance;
		if (licenseVerificationManager != null)
		{
			licenseVerificationManager.Verify(License);
		}
	}

	public void License(VerificationEventArgs eArgs)
	{
	}

	private bool CheckForInternetConnection()
	{
		WebClient webClient = null;
		Stream stream = null;
		try
		{
			webClient = new WebClient();
			stream = webClient.OpenRead("http://www.google.com");
			return true;
		}
		catch (Exception)
		{
			return false;
		}
		finally
		{
			if (webClient != null)
			{
				webClient.Dispose();
			}
			if (stream != null)
			{
				stream.Dispose();
			}
		}
	}

	public bool CheckLicense()
	{
		return true;
	}
}
